package lagou.cn.test
import scala.util.control.Breaks._

object Check {

    def main(args: Array[String]): Unit = {
      println("**************************")
      println("********猜拳，开始*********")
      println("**************************")
      //1. 选取对战角色
      println("请选择对战角色:（1.刘备 2.关羽 3.张飞）")
      var role = scala.io.StdIn.readInt()
      while (role != 1 && role != 2 && role != 3) {
        println("没有这个选项，请重新输入:")
        role = scala.io.StdIn.readInt()
      }
      println(s"您选择与${if (role == 1) "刘备" else if (role == 2) "关羽" else "张飞"}")
      var ok = ""
      var result = ""
      var flag = true
      var cishu = 0
      breakable {
        while (true) {
          println("要开始吗？ y/n")
          ok = scala.io.StdIn.readLine()
          if (ok == "n") {
            break()
          }else {
            println("游戏开始")
            println("请出拳！1.石头 2.剪刀 3.布 ")}
          result = scala.io.StdIn.readLine()
          if (result != "1" && result != "2" && result != "3") {
          //4 . 循环对战，当输入“n”时，终止对战，并显示对战结果

          } else  {

              //3. 猜拳结束算分，平局都加一分，获胜加二分，失败不加分
              var computer = scala.util.Random.nextInt(3) + 1 + ""
              var sco = if (computer == result) 1 else {
                if ((result.toInt - computer.toInt) == 1 || (result.toInt - computer.toInt) == -2) 0 else 2
              }
              println(s"你出的是${if (result == "1") "石头" else if (result == "2") "剪刀" else "布"}")
              println(s"${if (role == 1) "刘备" else if (role == 2) "关羽" else "张飞"}出拳！" )
              println(s"${if (role == 1) "刘备" else if (role == 2) "关羽" else "张飞"}出拳：[${if (computer == "1") "石头" else if (computer == "2") "剪刀" else "布"}]," )
              println( s"结果您是[${if (sco == 2) "恭喜，你赢了！" else if (sco == 1) "和局！ 下次继续努力！" else "失败"}]")
              cishu += 1
            }
          }
        }
        println("退出游戏！")
        println("------------------------")
        println(s"${if (role == 1) "刘备" else if (role == 2) "关羽" else "张飞"} VS 游客")
        println(s"对战次数 $cishu 次")

      }

}
